import requests
import parsel

headers = {
        'Cookie': 't=f8e5c504a4e96b4ddcd519559ac24870; r=1066; XSRF-TOKEN=eyJpdiI6IkdLWWRpRVlmUzk2RVNIWVVENms0V2c9PSIsInZhbHVlIjoiVDcwbjlCNEVnUFZHdG5XREJ1VWIxZWlNN2dPTG5XSEh4UTIycTdaQ2V2aWF1UkpPU2dpeEU0Z3lQaVZJazhscWt1XC80cEt0eVJcL2doaXVlZXZBaWh3U2hGNlU2VXlSQzRrY3lcL1BjdkV3b2dMUFR2MTk1UHhcL0tNY2NORVJ3MGdZIiwibWFjIjoiOTM4YWZmNTAyZDBhY2RkMmQzOWQyMDAzZDAyNzhjMDk5ZWZhZWJjMjAzMDI3MzI3MDI2ZGZjYjQ3MDJhYTZlMCJ9; win4000_session=eyJpdiI6IklKSlVWMlFHTkkzaExpdEVGYlNweUE9PSIsInZhbHVlIjoibVpxYjhHWGhocVBYZFwvQW8rZzFzdG1Td3BuRzVLbzRjTHdQd2J4aTJHWXJcL1hpTk5YNU9GUnNTSHpVU2p3Y3UxcDE3UE1UV3BzT2hJektjM2R6K1l0NGR4RmFiY1NhZlIzR0VzakhEQzdmT3Z4UjR2ZDdjZ2RJYlhcL2xzY1J4TnMiLCJtYWMiOiI2NGUyMWEwOWIxOWM1NWJkNmI1OTJlYTJjYmRjMjI1MDdkNWRmOTc5NWMyN2NlNmM0MzRkZThmMjYxOTQ2MjI0In0%3D',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36'
}

base_url ='http://www.win4000.com/mobile_2340_0_0_1.html'

response = requests.get(url=base_url, headers=headers)
data = response.text
#print(data)

html_data = parsel.Selector(data)
data_list = html_data.xpath('//div[@class="Left_bar"]//ul[@class="clearfix"]/li/a/@href').extract()
#print(data_list)

for alist in data_list:
       #print(alist)
        response_2 = requests.get(url=alist, headers=headers).text

        html_2 = parsel.Selector(response_2)
        img_url = html_2.xpath('//div[@class="pic-meinv"]/a/img/@src').extract_first()
        #print(img_url)

        img_data = requests.get(url=img_url, headers=headers).content

        file_name = img_url.split('/')[-1]

        with open('img\\' + file_name, 'wb') as f:
                print(file_name)
                f.write(img_data)


